const {
	defineConfig
} = require('@vue/cli-service');
const os = require('os');
const ifaces = os.networkInterfaces();
const platform = os.platform();

const getLocalIP = () => {
	let ip;
	if (platform === 'win32') {
		for (let dev in ifaces) {
			if (dev === '以太网' || dev.includes("WLAN")) {
				for (let j = 0; j < ifaces[dev].length; j++) {
					if (ifaces[dev][j].family === 'IPv4') {
						ip = ifaces[dev][j].address;
						break;
					}
				}
			}
		}
	}
	if (platform === 'linux') {
		for (let dev in ifaces) {
			if (dev !== 'lo') {
				for (let j = 0; j < ifaces[dev].length; j++) {
					if (ifaces[dev][j].family === 'IPv4') {
						ip = ifaces[dev][j].address;
						break;
					}
				}
			}
		}
	}
	if (platform === 'darwin') {
		for (let dev in ifaces) {
			if (!dev.includes('lo')) {
				for (let j = 0; j < ifaces[dev].length; j++) {
					if (ifaces[dev][j].family === 'IPv4') {
						ip = ifaces[dev][j].address;
						break;
					}
				}
			}
		}
	}
	return ip;
}

module.exports = defineConfig({
	transpileDependencies: true,
	devServer: {
		host: getLocalIP(),
		hot: true, //自动保存
		open: false, //自动启动
		port: 8080, //默认端口号
	},
	configureWebpack: {
		// devtool
		devtool:(process.env.NODE_ENV === 'development' ? 'eval-source-map' : undefined)
	}
})
